package main

import (
	"fmt"
	"reflect"
)

// you can also use imports, for example:
// import "fmt"
// import "os"

// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")

func ListNumEq(a []int, n int) int {
	res := 0
	for _, v := range a {
		if v == n {
			res += 1
		}
	}
	return res
}

func DeepCopy(src, dst [][]int, N int) error {
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			dst[i][j] = src[i][j]
		}
	}
	return nil
}

func Solution(A []int, B []int, N int) int {
	// Implement your solution here
	city_map := make([][]int, N)
	for i := 0; i < N; i++ {
		city_map[i] = make([]int, N)
	}

	for i := 0; i < N; i++ {
		begin, end := A[i]-1, B[i]-1
		fmt.Print(begin, " ", end)
		city_map[begin][end] = 1
		city_map[end][begin] = 1
	}

	last_city_map := make([][]int, N)
	for i := 0; i < N; i++ {
		last_city_map[i] = make([]int, N)
	}

	for !reflect.DeepEqual(last_city_map, city_map) {
		fmt.Println(city_map)
		_ = DeepCopy(city_map, last_city_map, N)
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				v := city_map[i][j]
				for x := 0; x < N; x++ {
					city_map[i][x] |= city_map[i][v]
				}
			}
		}
	}

	fmt.Println(city_map)
	// fmt.Println(reflect.DeepEqual(last_res, res))
	return 1
}

func main() {
	r := Solution([]int{1, 2, 3, 4}, []int{2, 3, 1, 4}, 4)
	fmt.Print(r, "\n")
}
